@include('admin.header')
<style>
    .search_product {
        max-height:248px;
        overflow-y: scroll;
    }
    .search_product > .item {
        width:80px;
        margin-right:5px;
        float:left;
    }
    .search_product > .item img {
        height:80px;
    }
    .search_product > .item .name {
        height:20px;
        overflow:hidden;
    }
</style>
<div class="margin-top-20">
    <form method="post" class="form-horizontal js-ajax-form user_register" action="/ucenter/user_register" novalidate="novalidate">       <fieldset>
            <div class="control-group"><label class="control-label">推荐人</label>
                <div class="controls">
                    <input type="number" name="introducer" value="" placeholder="请填写推荐人手机号码"><span class="form-required" >*</span>
                </div>
            </div>

            <div class="control-group"><label class="control-label">用户手机号码</label>
                <div class="controls">
                    <input type="number" name="mobile_no" value="" placeholder="请填写用户手机号码"><span class="form-required" >*</span>
                </div>
            </div>

        </fieldset>
        <div class="form-actions">
            <button type="button" class="btn btn-primary js-ajax-submit">保存</button></div>
    </form>
</div>
<script src="/js/layer/2.4/dialog.js"></script>
<script>
$(function () {
    $("input[name='introducer'],input[name='mobile_no']").keydown(function(event){
        if(event.keyCode == 13) {
            var introducer = $('input[name="introducer"]').val();
            var mobile_no = $('input[name="mobile_no"]').val();
            // var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;

            //数据校验
            if(!introducer) {
                dialog.error('请填写推荐人手机号码');
                return false;
            }
            if(!mobile_no) {
                dialog.error('请填写用户手机号码');
                return false;
            }

            //手机格式校验
            // if(!myreg.test($("input[name='introducer']").val())) { 
            //     dialog.error('请填写有效的手机号码');
            //     return false; 
            // }
            // if(!myreg.test($("input[name='mobile_no']").val())) { 
            //     dialog.error('请填写有效的手机号码');
            //     return false; 
            // } 

            //发送异步请求
            $.post(
                "{{url('ucenter/user_register')}}",
                {"introducer":introducer,"mobile_no":mobile_no},
                function(data) {
                    // alert(data);return false;
                    if(data.info == '注册成功') {
                        dialog.success(data.info,"{{url('ucenter/user_register')}}");
                    }else {
                        dialog.error(data.info);
                    }
                },
                "json"
            );
            return false;
        }
    });

    //获取表单数据
    $('.js-ajax-submit').click(function() {
        var introducer = $('input[name="introducer"]').val();
        var mobile_no = $('input[name="mobile_no"]').val();

        //数据校验
        if(!introducer) {
            dialog.error('请填写推荐人手机号码');
            return false;
        }
        if(!mobile_no) {
            dialog.error('请填写用户手机号码');
            return false;
        }

        //发送异步请求
        $.post(
            "{{url('ucenter/user_register')}}",
            {"introducer":introducer,"mobile_no":mobile_no},
            function(data) {
                if(data.info == '注册成功') {
                    dialog.success(data.info,"{{url('ucenter/user_register')}}");
                }else {
                    dialog.error(data.info);
                }
            },
            "json"
        );
    });
});
</script>